package logic

import (
	"context"
	"gorm.io/gorm"
	"user-login-reg/model/mysql"

	"user-login-reg/regrpc/internal/svc"
	"user-login-reg/regrpc/regrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsAddLogic {
	return &GoodsAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 用户添加
func (l *GoodsAddLogic) GoodsAdd(in *regrpc.GoodsAddRequest) (*regrpc.GoodsAddResponse, error) {
	// todo: add your logic here and delete this line
	goods := mysql.Goods{
		Model:      gorm.Model{},
		GoodsName:  in.GoodsName,
		GoodsPrice: in.GoodsPrice,
		GoodsNum:   int(in.GoodsNum),
		UserId:     int(in.UserId),
	}
	err := goods.GoodsAdd(mysql.DB)
	if err != nil {
		return nil, err
	}
	return &regrpc.GoodsAddResponse{
		UserId: int64(goods.ID),
	}, nil
}
